package buttons.view;

import processing.core.PApplet;
import processing.core.PFont;

public class V_TextButton extends V_Button {

	protected PFont B_Font;
	protected String defaultFontName = "verdana-10";
	protected int fontSize = 10;
	protected int alignment = 1;
	
	public V_TextButton(String n, float xWidth, float yHeight) {
		super(n, xWidth, yHeight);
	}
		
	@Override
	public void display(PApplet p)
	{
		super.display(p);
		if (visible)
		{
			if(B_Font != null)
		    {
				p.fill(0,0,0,transp); 
			    p.textFont(B_Font);
			    
				switch(alignment) {
					case 0: // left justified
						p.text(name, xLoc+2, yLoc+fontSize);
						break;
					case 1: // Centre the name in the middle of the button:
						p.text(name, xLoc+(xSize/2)-(p.textWidth(name)/2), yLoc+fontSize);
						break;
					case 2: // right justified
						p.text(name, xLoc+xSize-p.textWidth(name)-2, yLoc+fontSize);
						break;
				}
		    }
		}
	}
	
	// a value between 0 and 2 where 0 is left justified, 1 is centered, and 2 is right justified
	public void setAlignment(int val)
	{
		alignment = Math.max(0, Math.min(2, val));
	}
	
	// use this "setName(...)" method when you want the button to use its default font.
	public void setName(String n, PApplet p)
	{
		name = n;
		B_Font = p.createFont(defaultFontName, fontSize);
	}
	// enable the use of the font by passing in the PApplet:
	public void useFont(PApplet p){
		B_Font = p.createFont(defaultFontName, fontSize);
	}
	public void setFont(PFont fnt){
		B_Font = fnt;
	}
	public void setFont(String fontName, int size, PApplet p){
		B_Font = p.createFont(fontName, size);
		fontSize = size;
	}
}
